package com.haiheng.library_base.db

import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.Update

/**
 *
 * @Des:剔旧
 * @Author: hwz
 * @Date:2023/8/1 0001
 * @Version: 1.0
 */
@Dao
interface BookRetirementDao {

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    suspend fun insert(recordTable: BookRetirementData): Long

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    suspend fun insertAll(bookInfoList: List<BookRetirementData>)

    @Delete
    suspend fun delete(recordTable: BookRetirementData): Int

    @Delete
    suspend fun deleteList(recordTableList : List<BookRetirementData>)
    @Update
    suspend fun update(recordTable: BookRetirementData): Int

    @Query("DELETE FROM book_retirement_table WHERE objInfo = :barCode")
    suspend fun deleteBookRetirementByBarCode(barCode: String):Int

    // 删除表中所有数据
    @Query("DELETE FROM book_retirement_table")
    suspend fun deleteAll()

    @Query("SELECT * FROM book_retirement_table")
    suspend fun queryAll():  List<BookRetirementData>

    @Query("SELECT * FROM book_retirement_table WHERE objInfo = :objInfo ORDER BY id DESC LIMIT 1")
    suspend fun findByKey(objInfo: String): BookRetirementData?

}